<?php
  if ($_POST['id']!='' && $_POST['full_name']!='') {
    $link = mysql_connect('', 'admin_xbq', 'nihao')
        or die('Could not connect: ' . mysql_error());
    echo "Connected successfully\n";

    mysql_query('use test;');
    $sql = 'INSERT INTO `staffroom` (`sr_ID`, `depart_ID`, `sr_short_name`, `sr_full_name`, 
    `sr_head_name`, `sr_head_duty`, `phone`, `email`, `sr_page`) VALUES (\''.$_POST['id'].'\',
    \''.$_POST['depart_id'].'\', \''.$_POST['short_name'].'\', \''.$_POST['full_name'].' \', \''.$_POST['head'].'\',
    \''.$_POST['duty'].'\', \''.$_POST['phone'].'\', \''.$_POST['email'].'\', \''.$_POST['page'].'\');';
    $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
    mysql_close($link);
    
    echo 'Please create next staff room.';
  }
?>

<form action="<?php echo $_SERVER['PHP_SELF'];?>?d_id=<?php echo $_GET['d_id'];?>" method="post">
  <table align="center" width="400">
    <tr>
      <td class="style3">Staff room ID:</td>
      <td align="right" class="style3"><input width="100" name="id" type="text" /></td>
    </tr>
    <tr>
      <td class="style3">Department ID:</td>
      <td align="right" class="style3"><input width="100" name="depart_id" type="text" /></td>
    </tr>
    <tr>
      <td class="style3">Staff room's short name:</td>
      <td align="right" class="style3"><input name="short_name" type="text" /></td>
    </tr>
    <tr>
      <td class="style3">Staff room's full name:</td>
      <td align="right" class="style3"><input  name="full_name" type="text" /></td>
    </tr>
    <tr>
      <td class="style3">Head of staff room:</td>
      <td align="right" class="style3"><input name="head" type="text" /></td>
    </tr>
    <tr>
      <td class="style3">Duty of staff room head:</td>
      <td align="right" class="style3">
        <select name="duty">
          <option value="Professor"> Professor </option>
          <option value="Associate professor"> Associate professor </option>
          <option value="Old teacher"> Old teacher </option>
          <option value="Assistant"> Assistant </option>
        </select>
      </td>
    </tr>
    <tr>
      <td class="style3">Staff room phone:</td>
      <td align="right" class="style3"><input name="phone" type="text" /></td>
    </tr>
    <tr>
      <td class="style3">Staff room e-mail:</td>
      <td align="right" class="style3"><input name="email" type="text" /></td>
    </tr>
    <tr>
      <td class="style3">Staff room homepage:</td>
      <td align="right" class="style3"><input name="page" type="text" /></td>
    </tr>
    <tr>
      <td class="style3" align="right"><input name="add" type="button" value="Reset" /></td>
      <td align="left" class="style3"><input name="add" type="submit" value="Add next" /></td>
    </tr>
  </table>
</form>
